package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark96Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark96 extends BaseMark {

    LayoutWatermark96Binding binding;

    public Mark96(@NonNull Context context) {
        super(context);
    }

    public Mark96(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark96(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark96Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark96Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "title96", binding.binding1);
        setText(binding.binding3, "time96", binding.binding2);
        setTime(binding.binding3, new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
        setText(binding.binding5, "didian96", binding.binding4);
        setText(binding.binding7, "unit96", binding.binding6);

        setText(binding.binding9, "area96", binding.binding8);
        setText(binding.binding11, "person96", binding.binding10);
        setText(binding.binding13, "result96", binding.binding12);

        setText(binding.binding15, "suggest96", binding.binding14);
        setText(binding.binding17, "desc96", binding.binding16);


        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title96", "标题"));
        list.add(new EditItem("time96", "时间"));
        list.add(new EditItem("didian96", "地点"));
        list.add(new EditItem("unit96", "单位"));

        list.add(new EditItem("area96", "巡查区域"));
        list.add(new EditItem("person96", "巡查人"));
        list.add(new EditItem("result96", "巡查结果"));
        list.add(new EditItem("suggest96", "整改建议"));
        list.add(new EditItem("desc96", "详细说明"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding3, new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
        } else {
            super.onValueChange(item);
        }
    }
}
